package com.tql.mall.product;

import com.tql.mall.common.constant.RedisConstant;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.ComponentScan;

/**
 * @Author: tyk
 * @Date: 2023/5/21 18:48
 * @Description:
 */
@SpringBootApplication
@EnableDiscoveryClient
@ComponentScan("com.tql.mall")
public class ServiceProductApplication implements CommandLineRunner {

    @Autowired
    private RedissonClient redissonClient;

    public static void main(String[] args) {
        SpringApplication.run(ServiceProductApplication.class, args);
    }

    /**
     * 初始化布隆过滤器
     */
    @Override
    public void run(String... args) throws Exception {
        // 获取布隆过滤器
        RBloomFilter<Object> bloomFilter = redissonClient.getBloomFilter(RedisConstant.BLOOM_FILTER);
        // 初始化布隆过滤器：元素个数和误判率
        bloomFilter.tryInit(1000, 0.001);
    }
}
